package com.iknow.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.iknow.IKnow;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.util.Loger;
import java.util.ArrayList;
import java.util.List;

public class IKProductFavoriteTable
{
  public static final String DELETE_TIME = "favorite_delete_time";
  public static final String FAVORITE_TIME = "favorite_time";
  public static final String ID = "id";
  public static final String ISFREE = "isFree";
  public static final String NAME = "name";
  public static final String OPENTYPE = "openType";
  public static final String PROVIDER = "provider";
  public static final String RANK = "rank";
  public static final String[] TABLE_COLUMNS;
  public static final String TABLE_NAME = "T_BD_PRODUCTFAVORITES";
  public static final String TAG = "IKProductFavoriteTable";
  public static final String URL = "url";
  public static final String USER_ID = "user_id";
  public Context ctx;

  static
  {
    String[] arrayOfString = new String[10];
    arrayOfString[0] = "user_id";
    arrayOfString[1] = "id";
    arrayOfString[2] = "url";
    arrayOfString[3] = "name";
    arrayOfString[4] = "provider";
    arrayOfString[5] = "rank";
    arrayOfString[6] = "isFree";
    arrayOfString[7] = "openType";
    arrayOfString[8] = "favorite_delete_time";
    arrayOfString[9] = "favorite_time";
    TABLE_COLUMNS = arrayOfString;
  }

  public IKProductFavoriteTable(Context paramContext)
  {
    this.ctx = paramContext;
  }

  public static ContentValues getContentValues(IKProductListDataInfo paramIKProductListDataInfo)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("user_id", IKnow.mSystemConfig.getString("user"));
    localContentValues.put("id", paramIKProductListDataInfo.getId());
    localContentValues.put("url", paramIKProductListDataInfo.getUrl());
    localContentValues.put("name", paramIKProductListDataInfo.getBookName());
    localContentValues.put("provider", paramIKProductListDataInfo.getBook_Provider());
    localContentValues.put("rank", Integer.valueOf(-1));
    localContentValues.put("isFree", paramIKProductListDataInfo.getIsFree());
    localContentValues.put("openType", paramIKProductListDataInfo.getOpenType());
    localContentValues.put("favorite_time", Long.valueOf(paramIKProductListDataInfo.getProductFavoriteTime()));
    localContentValues.put("favorite_delete_time", Long.valueOf(paramIKProductListDataInfo.getProductFavoriteDeleteTime()));
    return localContentValues;
  }

  private SQLiteDatabase getDataBase()
  {
    return IKnowDatabaseHelper.getDatabase(this.ctx);
  }

  public void addProduct(Context paramContext, IKProductListDataInfo paramIKProductListDataInfo)
  {
    if (-1L == getDataBase().insert("T_BD_PRODUCTFAVORITES", null, getContentValues(paramIKProductListDataInfo)))
      Loger.d("DB", "addProduct fail!!");
  }

  public void deleteAll()
  {
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = "T_BD_PRODUCTFAVORITES";
    String str = String.format("delete from %s", arrayOfObject);
    getDataBase().execSQL(str);
  }

  public List<IKProductListDataInfo> getProduct()
  {
    ArrayList localArrayList = new ArrayList();
    Cursor localCursor = getDataBase().query("T_BD_PRODUCTFAVORITES", TABLE_COLUMNS, null, null, null, null, null);
    localCursor.moveToFirst();
    while (true)
    {
      if (localCursor.isAfterLast())
      {
        localCursor.close();
        return localArrayList;
      }
      IKProductListDataInfo localIKProductListDataInfo = new IKProductListDataInfo();
      localIKProductListDataInfo.setUserId(localCursor.getString(localCursor.getColumnIndex("user_id")));
      localIKProductListDataInfo.setId(localCursor.getString(localCursor.getColumnIndex("id")));
      localIKProductListDataInfo.setUrl(localCursor.getString(localCursor.getColumnIndex("url")));
      localIKProductListDataInfo.setBookName(localCursor.getString(localCursor.getColumnIndex("name")));
      localIKProductListDataInfo.setBook_Provider(localCursor.getString(localCursor.getColumnIndex("provider")));
      localIKProductListDataInfo.setRank(localCursor.getFloat(localCursor.getColumnIndex("rank")));
      localIKProductListDataInfo.setIsFree(localCursor.getString(localCursor.getColumnIndex("isFree")));
      localIKProductListDataInfo.setOpenType(localCursor.getString(localCursor.getColumnIndex("openType")));
      localIKProductListDataInfo.setProductFavoriteTime(localCursor.getLong(localCursor.getColumnIndex("favorite_time")));
      localIKProductListDataInfo.setProductFavoriteDeleteTime(localCursor.getLong(localCursor.getColumnIndex("favorite_delete_time")));
      localArrayList.add(localIKProductListDataInfo);
      localCursor.moveToNext();
    }
  }

  public boolean isProductFavorite(String paramString1, String paramString2)
  {
    String str = "id = '" + paramString1 + "'";
    SQLiteDatabase localSQLiteDatabase = getDataBase();
    String[] arrayOfString = new String[1];
    arrayOfString[0] = "id";
    Cursor localCursor = localSQLiteDatabase.query("T_BD_PRODUCTFAVORITES", arrayOfString, str, null, null, null, null);
    boolean bool = localCursor.moveToNext();
    localCursor.close();
    return bool;
  }

  public void removeProduct(IKProductListDataInfo paramIKProductListDataInfo)
  {
    if ((paramIKProductListDataInfo == null) || (paramIKProductListDataInfo.getIsFavorite() == 0));
    while (true)
    {
      return;
      String str = "id = '" + paramIKProductListDataInfo.getId() + "'";
      getDataBase().delete("T_BD_PRODUCTFAVORITES", str, null);
    }
  }

  public void removeProduct(String paramString1, String paramString2)
  {
    if (paramString1 == null);
    while (true)
    {
      return;
      String str = "id = '" + paramString1 + "'";
      getDataBase().delete("T_BD_PRODUCTFAVORITES", str, null);
    }
  }
}